<template>
	<div class="warp">
		<el-row :gutter="24">
			<el-form ref="elForm" :model="formData" :rules="rules" size="medium " label-width="10px">
				<!-- 关键字 -->
				<el-col :span="5">
					<el-form-item label-width="70px" label="关键字" prop="field102">
						<el-input v-model="formData.field102" placeholder="维修申请单名称、单号" clearable :style="{ width: '100%' }"> </el-input>
					</el-form-item>
				</el-col>
				<!-- 申请船舶 -->
				<el-col :span="5">
					<el-form-item prop="field101" label-width="70px" label="申请船舶">
						<el-select v-model="formData.field101" placeholder="请选择申请船舶" clearable :style="{ width: '100%' }">
							<el-option v-for="(item, index) in field101Options" :key="index" :label="item.label" :value="item.value" :disabled="item.disabled"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<!-- 申请部门 -->
				<el-col :span="5">
					<el-form-item prop="field101" label-width="70px" label="部门">
						<el-select v-model="formData.field101" placeholder="请选择部门" clearable :style="{ width: '100%' }">
							<el-option v-for="(item, index) in field101Options" :key="index" :label="item.label" :value="item.value" :disabled="item.disabled"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<!-- 紧急程度 -->
				<el-col :span="5">
					<el-form-item prop="field101" label-width="70px" label="紧急程度">
						<el-select v-model="formData.field101" placeholder="请选择紧急程度" clearable :style="{ width: '100%' }">
							<el-option v-for="(item, index) in field101Options" :key="index" :label="item.label" :value="item.value" :disabled="item.disabled"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<!-- 自购状态 -->
				<el-col :span="4">
					<el-form-item prop="field101" label-width="70px" label="状态">
						<el-select v-model="formData.field101" placeholder="请选择状态" clearable :style="{ width: '100%' }">
							<el-option v-for="(item, index) in field101Options" :key="index" :label="item.label" :value="item.value" :disabled="item.disabled"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<!-- 维修类型 -->
				<el-col :span="5">
					<el-form-item prop="field101" label-width="70px" label="维修类型">
						<el-select v-model="formData.field101" placeholder="请选择维修类型" clearable :style="{ width: '100%' }">
							<el-option v-for="(item, index) in field101Options" :key="index" :label="item.label" :value="item.value" :disabled="item.disabled"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<!-- 时间范围 -->
				<el-col :span="10">
					<el-form-item label-width="70px" label="时间范围" prop="field103">
						<el-date-picker
							type="daterange"
							v-model="formData.field103"
							format="yyyy-MM-dd"
							value-format="yyyy-MM-dd"
							:style="{ width: '100%' }"
							start-placeholder="开始日期"
							end-placeholder="结束日期"
							range-separator="至"
							clearable
						></el-date-picker>
					</el-form-item>
				</el-col>
			</el-form>
		</el-row>

		<el-button size="medium" icon="el-icon-search" type="primary" @click="submitForm">查询</el-button>
		<el-button size="medium" icon="el-icon-delete" @click="resetForm">重置</el-button>
		<el-button size="medium" icon="el-icon-plus" type="primary" @click="centerDialogVisible = true">新增</el-button>
		<el-dialog title="新增维修申请" :visible.sync="centerDialogVisible" width="800px" center>
			<div>
				<el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="80px">
					<!-- 申请船舶 -->
					<el-row :gutter="24" class="layout-items-center">
						<el-col :span="12">
							<el-form-item prop="field101" label="申请名称">
								<el-input v-model="formData.name"></el-input>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item prop="field101" label="申请船舶">
								<el-select v-model="formData.field101" placeholder="请选择申请船舶" clearable>
									<el-option v-for="(item, index) in field101Options" :key="index" :label="item.label" :value="item.value" :disabled="item.disabled"></el-option>
								</el-select>
							</el-form-item>
						</el-col>

						<!-- 申请部门 -->
						<el-col :span="12">
							<el-form-item prop="field101" label="申请部门">
								<el-select v-model="formData.field101" placeholder="请选择申请部门" clearable>
									<el-option v-for="(item, index) in field101Options" :key="index" :label="item.label" :value="item.value" :disabled="item.disabled"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item prop="field101" label="紧急程度">
								<el-radio-group v-model="formData.radio3" size="small">
									<el-radio label="1" border>正常</el-radio>
									<el-radio label="2" border>紧急</el-radio>
								</el-radio-group>
							</el-form-item>
						</el-col>

						<el-col :span="24">
							<el-form-item label="维修原因">
								<el-input type="textarea" v-model="formData.desc"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
				</el-form>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button @click="centerDialogVisible = false">取 消</el-button>
				<el-button type="primary" @click="centerDialogVisible = false">确 定</el-button>
			</div>
		</el-dialog>
		<el-table :data="tableData" style="width: 100%; margin: 20px 0" max-height="500" border>
			<el-table-column fixed type="index" label="#" width="50" align="center"> </el-table-column>
			<el-table-column fixed prop="date" label="维修申请单名称" width="150" align="center"> </el-table-column>
			<el-table-column prop="name" label="申请单号" width="150" align="center"> </el-table-column>
			<el-table-column prop="province" label="申请船舶" width="150" align="center"> </el-table-column>
			<el-table-column prop="city" label="部门" width="150" align="center"> </el-table-column>
			<el-table-column prop="type" label="维修类型" width="150" align="center"> </el-table-column>
			<el-table-column prop="address" label="紧急程度" width="150" align="center"> </el-table-column>
			<el-table-column prop="zip" label="预计维修日期" width="150" align="center"> </el-table-column>
			<el-table-column prop="zip" label="预计维修地点" width="150" align="center"> </el-table-column>
			<el-table-column prop="zip" label="状态" width="150" align="center"> </el-table-column>
			<el-table-column prop="zip" label="维修订单" width="150" align="center">
				<template slot-scope="scope">
					<el-button @click.native.prevent="toSettlement(scope.$index, tableData)" size="medium" type="primary" plain :disabled="scope.row.type === '自修'"> 查看 </el-button>
				</template>
			</el-table-column>
			<el-table-column label="操作" width="210" fixed="right" align="center">
				<template slot-scope="scope">
					<el-button @click.native.prevent="drawer = true" size="medium" type="primary" plain>维修流程</el-button>

					<el-button @click.native.prevent="deleteRow(scope.$index, tableData)" type="danger" plain size="medium">删除</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-drawer title="维修流程" :visible.sync="drawer" :direction="direction" size="90%">
			<maintenancePlan></maintenancePlan>
		</el-drawer>
	</div>
</template>

<script>
	import maintenancePlan from "./components/maintenancePlan.vue";

	export default {
		components: {
			maintenancePlan,
		},
		data() {
			return {
				formData: {
					field101: undefined,
					field102: undefined,
					field103: undefined,
					field105: undefined,
					field106: [1],
				},
				rules: {
					field101: [],
					field102: [
						{
							message: "搜索关键字",
							trigger: "blur",
						},
					],
					field106: [],
				},
				field101Options: [
					{
						label: "自修",
						value: 1,
					},
					{
						label: "厂修",
						value: 2,
					},
				],
				field106Options: [
					{
						label: "隐藏其他人草稿单",
						value: 1,
					},
				],
				checked: false,
				tableData: [
					{
						date: "SP-S25020601",
						name: "RA-25011901",
						province: "华福油",
						city: "轮机部",
						type: "自修",
						address: "紧急",
						zip: "2025-02-06",
					},
					{
						date: "压载舱",
						name: "RA-25011901",
						province: "华福油",
						city: " 轮机部",
						type: "厂修",
						address: "紧急",
						zip: "2025-02-06",
					},
					{
						date: "2016-05-04",
						name: "王小虎",
						province: "上海",
						city: "普陀区",
						address: "上海市普陀区金沙江路 1518 弄",
						zip: 200333,
					},
					{
						date: "2016-05-01",
						name: "王小虎",
						province: "上海",
						city: "普陀区",
						address: "上海市普陀区金沙江路 1518 弄",
						zip: 200333,
					},
					{
						date: "2016-05-08",
						name: "王小虎",
						province: "上海",
						city: "普陀区",
						address: "上海市普陀区金沙江路 1518 弄",
						zip: 200333,
					},
					{
						date: "2016-05-06",
						name: "王小虎",
						province: "上海",
						city: "普陀区",
						address: "上海市普陀区金沙江路 1518 弄",
						zip: 200333,
					},
					{
						date: "2016-05-07",
						name: "王小虎",
						province: "上海",
						city: "普陀区",
						address: "上海市普陀区金沙江路 1518 弄",
						zip: 200333,
					},
				],
				centerDialogVisible: false,
				radio: "1",
				isPreparation: false,
				isDisabled: false,
				drawer: false,
				direction: "rtl",
			};
		},
		created() {},
		methods: {
			submitForm() {
				this.$refs["elForm"].validate((valid) => {
					if (!valid) return;
					// TODO 提交表单
				});
			},
			resetForm() {
				this.$refs["elForm"].resetFields();
			},
			isSelf(e) {
				console.log(e);
				if (e == 1) {
					this.isPreparation = true;
				} else {
					this.isPreparation = false;
				}
			},
			toSettlement() {
				this.$router.push({
					path: "/maintenance/settlement",
					params: {},
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	.warp {
		padding: 30px 20px;
		background-color: white;
		margin: 15px;
		border-radius: 20px;
		height: calc(100vh - 120px);
		overflow: auto;
	}
	::v-deep .is-success {
		color: #13ce66;
	}
	::v-deep .is-process {
		color: #2a61ff;
	}
	.drawer-content {
		padding: 20px;
		.drawer-txt {
			font-size: 15px;
			font-weight: bold;
			color: #606266;
			line-height: 35px;
			span {
				font-weight: 400;
				color: #777;
				font-size: 14px;
			}
		}
	}
</style>
